#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e3 + 10;
int arr[N];
int f[N];
int n;
int main()
{
	cin >> n;
	int ma = -1e9;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	for (int i = 0; i < n; i++) {
		f[i] = arr[i];
		for (int j = 0; j < i; j++) {
			if (arr[i] > arr[j]) {
				f[i] = max(f[i], f[j] + arr[i]);
			}
		}
		ma = max(ma, f[i]);
	}
	cout << ma << endl;
	return 0;
}